package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 单选题审核任务实体类
 * 对应数据库表：sc_review_tasks
 *
 * 根据B-02-03-03单选题管理子模块设计文档实现
 * 管理单选题的审核任务信息，包括审核状态、审核人、审核结果等。
 * 支持单选题的完整审核流程管理。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "sc_review_tasks")
@Comment("单选题审核任务表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SingleChoiceReviewTask {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 任务唯一标识符
     */
    @NotBlank(message = "任务ID不能为空")
    @Size(max = 50, message = "任务ID长度不能超过50个字符")
    @Column(name = "task_id", nullable = false, length = 50, unique = true)
    private String taskId;

    /**
     * 关联的单选题ID
     */
    @NotBlank(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false)
    private String questionId;

    /**
     * 任务类型（CONTENT_REVIEW-内容审核，QUALITY_REVIEW-质量审核，CHANGE_REVIEW-变更审核）
     */
    @NotBlank(message = "任务类型不能为空")
    @Size(max = 30, message = "任务类型长度不能超过30个字符")
    @Column(name = "task_type", nullable = false, length = 30)
    private String taskType;

    /**
     * 任务状态（PENDING-待分配，ASSIGNED-已分配，IN_PROGRESS-审核中，COMPLETED-已完成，APPROVED-已通过，REJECTED-已拒绝）
     */
    @NotBlank(message = "任务状态不能为空")
    @Size(max = 20, message = "任务状态长度不能超过20个字符")
    @Column(name = "task_status", nullable = false, length = 20)
    private String taskStatus;

    /**
     * 任务优先级（1-最高，2-高，3-中，4-低，5-最低）
     */
    @NotNull(message = "任务优先级不能为空")
    @Column(name = "priority", nullable = false)
    private Integer priority;

    /**
     * 审核人ID
     */
    @Column(name = "reviewer_id")
    private Long reviewerId;

    /**
     * 审核人姓名
     */
    @Size(max = 50, message = "审核人姓名长度不能超过50个字符")
    @Column(name = "reviewer_name", length = 50)
    private String reviewerName;

    /**
     * 审核人角色（CONTENT_REVIEWER-内容审核员，QUALITY_REVIEWER-质量审核员，ADMIN-管理员）
     */
    @Size(max = 30, message = "审核人角色长度不能超过30个字符")
    @Column(name = "reviewer_role", length = 30)
    private String reviewerRole;

    /**
     * 任务分配时间
     */
    @Column(name = "assign_time")
    private LocalDateTime assignTime;

    /**
     * 审核开始时间
     */
    @Column(name = "start_time")
    private LocalDateTime startTime;

    /**
     * 审核完成时间
     */
    @Column(name = "complete_time")
    private LocalDateTime completeTime;

    /**
     * 任务截止时间
     */
    @Column(name = "deadline_time")
    private LocalDateTime deadlineTime;

    /**
     * 审核结果（APPROVE-通过，REJECT-拒绝，RETURN-退回修改，SKIP-跳过）
     */
    @Size(max = 20, message = "审核结果长度不能超过20个字符")
    @Column(name = "review_result", length = 20)
    private String reviewResult;

    /**
     * 审核意见
     */
    @Column(name = "review_comment", columnDefinition = "TEXT")
    private String reviewComment;

    /**
     * 审核评分（1-5分）
     */
    @Column(name = "review_score")
    private Integer reviewScore;

    /**
     * 审核标签（JSON格式）
     */
    @Column(name = "review_tags", columnDefinition = "TEXT")
    private String reviewTags;

    /**
     * 审核详细数据（JSON格式）
     */
    @Column(name = "review_details", columnDefinition = "TEXT")
    private String reviewDetails;

    /**
     * 任务创建人ID
     */
    @NotBlank(message = "任务创建人ID不能为空")
    @Size(max = 50, message = "任务创建人ID长度不能超过50个字符")
    @Column(name = "creator_id", nullable = false, length = 50)
    private String creatorId;

    /**
     * 任务创建人姓名
     */
    @Size(max = 50, message = "任务创建人姓名长度不能超过50个字符")
    @Column(name = "creator_name", length = 50)
    private String creatorName;

    /**
     * 任务创建原因
     */
    @Size(max = 200, message = "任务创建原因长度不能超过200个字符")
    @Column(name = "creation_reason", length = 200)
    private String creationReason;

    /**
     * 预计审核时长（分钟）
     */
    @Column(name = "estimated_duration_minutes")
    private Integer estimatedDurationMinutes;

    /**
     * 实际审核时长（分钟）
     */
    @Column(name = "actual_duration_minutes")
    private Integer actualDurationMinutes;

    /**
     * 任务描述
     */
    @Column(name = "task_description", columnDefinition = "TEXT")
    private String taskDescription;

    /**
     * 任务要求（JSON格式）
     */
    @Column(name = "task_requirements", columnDefinition = "TEXT")
    private String taskRequirements;

    /**
     * 重试次数
     */
    @Column(name = "retry_count", nullable = false)
    private Integer retryCount;

    /**
     * 最大重试次数
     */
    @Column(name = "max_retry_count", nullable = false)
    private Integer maxRetryCount;

    /**
     * 任务元数据（JSON格式）
     */
    @Column(name = "metadata", columnDefinition = "TEXT")
    private String metadata;

    /**
     * 软删除标识
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 创建人
     */
    @Size(max = 50, message = "创建人长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

}